// dialog.js
function confirmDialog(message, onConfirm, onCancel) {
	const dialogHtml = `
      <div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <h5 class="modal-title" id="confirmModalLabel">确认</h5>
                      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body">${message}</div>
                  <div class="modal-footer">
                      <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                      <button type="button" class="btn btn-danger" id="confirmBtn">删除</button>
                  </div>
              </div>
          </div>
      </div>
  `;

	document.body.insertAdjacentHTML('beforeend', dialogHtml);
	const confirmModal = new bootstrap.Modal(
		document.getElementById('confirmModal')
	);

	document.getElementById('confirmBtn').onclick = () => {
		onConfirm();
		confirmModal.hide();
		document.getElementById('confirmModal').remove();
	};

	confirmModal.show();
}
